package com.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * 677. 键值映射
 * 使用HashMap存储key-value暴力扫描
 *
 * @author fy
 * @date 2022/4/19 14:38
 */
public class Solution677_1 {

    class MapSum {

        Map<String, Integer> map;

        public MapSum() {
            map = new HashMap<>();
        }

        public void insert(String key, int val) {
            map.put(key, val);
        }

        public int sum(String prefix) {
            int res = 0;
            for (String s : map.keySet()) {
                if (s.startsWith(prefix)) {
                    res += map.get(s);
                }
            }
            return res;
        }

    }

}
